<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>

<body>
  <div id="app">
    <home-page></home-page>
  </div>
  <script src="./vue.global.js"></script>
  <script src="./axios.js"></script>
  <script>
    // https://api.it120.cc/conner
    const { createApp } = Vue;
    const app = createApp();
    const HomePage = {
      template: `
        <div>
          <h2>这是首页</h2>
          <ul>
            <li v-for="cate in cates" :key="cate.id">
              <h4>{{cate.name}}</h4>  
              <img :src="cate.icon" width="100"/>
            </li>  
          </ul>
        </div>
      `,
      data() {
        return {
          // 1在data定义初始值接收请求数据
          cates: []
        }
      },
      methods: {
        // 2 methods中定义方法发送请求
        getCates() {
          axios.get('https://api.it120.cc/conner/shop/goods/category/all').then(res=> {
            if(res.data.code === 0) {
              this.cates = res.data.data
            }
          })
        }
      },
      created() {
        this.getCates();
      }
    }
    app.component('HomePage', HomePage)

    app.mount('#app')

  </script>
</body>

</html>